package com.lkd.http.controller;

import com.lkd.entity.VendingMachineEntity;
import com.lkd.service.VendingMachineService;
import com.lkd.vo.Pager;
import com.lkd.vo.SkuVO;
import com.lkd.vo.VmVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/vm")
public class VendingMachineController {

    @Autowired
    private VendingMachineService vendingMachineService;

   /*
   * 分页查询
   * */
   @GetMapping("/search")
   public Pager<VendingMachineEntity> search(
           @RequestParam(defaultValue = "1") Integer pageIndex,
           @RequestParam(defaultValue = "10") Integer pageSize,
           Integer status,
           String innerCode
   ){
       //调用service返回
       return vendingMachineService.search(pageIndex,pageSize,status,innerCode);

   }


    /*
    * 售货机新增
    * */
   @PostMapping
   public void saveVM(@RequestBody VendingMachineEntity vm){
       //调用service
       vendingMachineService.saveVM(vm);
   }

    /*
    * feigh内部调用，根据设备编号查询vo
    * */
   @GetMapping("/findByInnerCode")
   public VmVO findByInnerCode(@RequestParam String innerCode){
       //调用service
       return vendingMachineService.findByInnerCode(innerCode);
   }


    //根据售货机innerCode查询商品列表
    @GetMapping("/skuList/{innerCode}")
    public List<SkuVO> findSkuListByInnerCode(@PathVariable("innerCode") String innerCode){
       return vendingMachineService.getSkuListByInnerCode(innerCode);
    }

}